module.exports = function($scope, $state, $stateParams,$resource,$modal,toaster){  
	/* 分页
        * ========================================= */
    $scope.maxSize = 5;             //最多显示多少个按钮
    $scope.bigCurrentPage = 1;      //当前页码
    $scope.itemsPerPage = 10         //每页显示几条
    $scope.searchform = {};
    $scope.getlist = function () {
        var para = {
            pageNo:$scope.bigCurrentPage, 
            pageSize:$scope.itemsPerPage
        };
        para = angular.extend($scope.searchform, para);
        $resource('/api/ac/ggc/touristFundsCapitalApplyService/findCapitalApplyByUserList', {}, {}).
        save(para,function(res) {
            if (res.errcode !== 0) {
                toaster.error({title:"",body:res.errmsg});
                return;
            }
            $scope.objs = res.data.results;
            $scope.bigTotalItems = res.data.totalRecord;
            $scope.objs.forEach(function(element) {
              // 调进度接口
              $resource('/api/ac/ggc/touristFundsCapitalApplyService/getCapitalApplyProgressInfo', {}, {}).
              save({'apply_id' : element.apply_id},function(res) {
                  if (res.errcode !== 0) {
                      toaster.error({title:"",body:res.errmsg});
                      return;
                  }
                  element.progress_state = res.data.state;
              })
              console.log(element);

            }, this);
        })
    };
     
    $scope.getlist();

    // 删除申请
    $scope.delete = function(apply_id) {
        if (confirm('确定要删除吗?')) {
            $resource('/api/as/ggc/touristFundsCapitalApplyAd/updateDel', {}, {}).            
            save({'apply_id':apply_id},function(res) {
                if (res.errcode !== 0) {
                    toaster.error({title:"",body:res.errmsg});
                    return;
                } 
                toaster.success({title:"",body:"删除成功"});                
                $scope.getlist();
            })
            return;
        } 
        
    };
    // 申请
    $scope.apply = function(apply_id){
      if (confirm('确定要申请该资金吗?')) {
        $resource('/api/as/ggc/touristFundsCapitalApplyAd/updateCapitalApplyYes', {}, {}).
        save({'apply_id': apply_id},function(res) {
            if (res.errcode !== 0) {
                toaster.error({title:"",body:res.errmsg});
                return;
            }
            console.log(res);
            toaster.success({title:"",body:"申请成功"});
            $scope.getlist();
        })
        return;
      } 
    }

    $scope.edit = function(item) {
        $scope.flag = 'edit';
        var modalInstance = $modal.open({
        template: require('../views/declareFund.html'),
        controller: 'declareFund',
        size: 'lg',
        resolve: {
            item: function () {
                return item;
            },
            flag: function () {
                return $scope.flag;
            },
         }
        });
        modalInstance.result.then(function (showResult) {	
            $scope.getlist();
        });
    };
    // 驳回理由
    $scope.rejectinfo = function(apply_id) {
        $scope.flag = 'info';
        var modalInstance = $modal.open({
        template: require('../views/common_reject.html'),
        controller: 'common_reject',
        size: 'xs',
        resolve: {
            apply_id: function () {
                return apply_id;
            },
            flag: function () {
                return $scope.flag;
            },
        }
        });
        modalInstance.result.then(function (showResult) {	
            $scope.getlist();
        });
    };



    
    

 

};